package com.mvvm.demo.di

import androidx.arch.core.executor.ArchTaskExecutor
import androidx.room.Room
import com.mvvm.demo.base.MvvmApplication
import com.mvvm.demo.db.UserDatabase
import com.mvvm.demo.db.UserInfoDao
import org.kodein.di.Kodein
import org.kodein.di.generic.bind
import org.kodein.di.generic.instance
import org.kodein.di.generic.provider
import org.kodein.di.generic.singleton

private const val DB_MODULE_TAG = "DBModule"

val dbModule = Kodein.Module(DB_MODULE_TAG) {

    bind<UserDatabase>() with singleton {
        Room.databaseBuilder(MvvmApplication.INSTANCE, UserDatabase::class.java, "user")
                .setTransactionExecutor(ArchTaskExecutor.getIOThreadExecutor())
                .fallbackToDestructiveMigration()
                .build()
    }
    bind<UserInfoDao>() with singleton {
        instance<UserDatabase>().userInfo()
    }
}